package com.xinchuang.service.targetSystem.Impl.damage;

import cn.hutool.core.collection.CollectionUtil;
import com.xinchuang.common.Result;
import com.xinchuang.common.ResultUtil;
import com.xinchuang.entity.targetSystem.system.TargetSubType;
import com.xinchuang.service.targetSystem.TargetSubTypeService;
import com.xinchuang.service.targetSystem.damage.DamageService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * TODO
 *
 * @author zkwczx
 * @version 1.0
 * @date 2024/5/17 19:20
 */
@Service
@RequiredArgsConstructor
public class DamageServiceImpl implements DamageService {

    private final TargetSubTypeService targetSubTypeService;

    @Override
    public Result getSubTypePull(String typeId) {
        List<Map<String, Object>> resultList = new ArrayList<>();
        List<TargetSubType> subTypes = targetSubTypeService.lambdaQuery().eq(TargetSubType::getParentId, typeId).list();
        if (CollectionUtil.isNotEmpty(subTypes)) {
            for (TargetSubType subType : subTypes) {
                Map<String, Object> map = new HashMap<>();
                map.put("label", subType.getTypeName());
                map.put("value", subType.getTypeId());
                resultList.add(map);
            }
        }
        return ResultUtil.success(resultList);
    }

}
